import { _decorator, Component, Node, Input, EventTouch } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ContextView')
export class ContextView extends Component {
    private isclick: boolean = false;
    start() {
        // this.node.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
        // this.node.on(Input.EventType.TOUCH_MOVE, this.scrollView, this);
        // this.node.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
        // console.log('加载完成',);
    }
    onDestroy() {
        this.node.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.off(Input.EventType.TOUCH_MOVE, this.scrollView, this);
        this.node.off(Input.EventType.TOUCH_END, this.onTouchEnd, this);
    }
    update(deltaTime: number) {

    }
    onTouchStart() {
        this.isclick = true;
    }
    scrollView(e: EventTouch) {
        if (this.isclick) {
            try {
                wx.getOpenDataContext().postMessage({ event: 'scroll', val: `${e.getDeltaY()}` });
            } catch (error) {
                console.log('error', error);
            }
        }
    }
    onTouchEnd() {
        this.isclick = false;
    }
}

